#include "stdint.h"
#include "stddef.h"
#include "stdio.h"
#include "stm32f4xx_ll_gpio.h"
#include "iot_uart.h"
#include "uart_test.h"
#include "los_task.h"
#include "los_compiler.h"
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "ohos_types.h"

void uart_entry()
{
    printf("----- uart test -----\r\n");
    IotUartAttribute param;
    param.baudRate = 115200;
    param.dataBits = IOT_UART_DATA_BIT_8;
    param.parity = IOT_UART_PARITY_NONE;
    param.stopBits = IOT_UART_STOP_BIT_1;
    IoTUartInit(2, &param);
    IoTUartWrite(2, "AT+RST\r\n", 8);
    uint8_t buf[16]={0};
	// 每隔1s读取15个字节的数据
    while(1){
        memset(buf, 0, 16);
        delay_ms(2000);
        IoTUartRead(2, buf, 15);
        printf("read buf is : ");
        for(uint8_t i=0; i<16; i++){
            printf("%c", buf[i]);
        }
        printf("\r\n");
    }
}

void uart_task()
{
    UINT32 uwRet = -1;
    UINT32 taskID = 0;
    TSK_INIT_PARAM_S stTask = {0};
    stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)uart_entry;
    stTask.uwStackSize = 0x1000;
    stTask.pcName = "uart task";
    stTask.usTaskPrio = 10;
    uwRet = LOS_TaskCreate(&taskID, &stTask);
    if (uwRet != LOS_OK) {
        printf("Task fs create failed\r\n");
    }
}